# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=yarn
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.22.19
pkgrel=1
pkgdesc="Fast, reliable, and secure dependency management (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://yarnpkg.com/"
license=("spdx:BSD-2-Clause")
depends=("${MINGW_PACKAGE_PREFIX}-nodejs")
source=("https://github.com/yarnpkg/${_realname}/releases/download/v${pkgver}/${_realname}-v${pkgver}.tar.gz"
        "0001-fhs.patch")
sha256sums=('732620bac8b1690d507274f025f3c6cfdc3627a84d9642e38a07452cc00e0f2e'
            '1f85c997390a9a83305300883a5b8b97856f748fc5b21e7ed75d47cb1ba809f4')

prepare() {
  cd "${srcdir}/${_realname}-v${pkgver}"

  patch -Np1 -i "${srcdir}/0001-fhs.patch"
}

package() {
  cd "${srcdir}/${_realname}-v${pkgver}"

  install -dm755  "${pkgdir}"/${MINGW_PREFIX}/lib/node_modules/yarn
  cp -R * "${pkgdir}"/${MINGW_PREFIX}/lib/node_modules/yarn

  install -dm755 "${pkgdir}"/${MINGW_PREFIX}/bin
  cp bin/yarn "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarn.cmd "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarnpkg "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarnpkg.cmd "${pkgdir}"/${MINGW_PREFIX}/bin/

  install -Dm644 LICENSE "${pkgdir}/${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 README.md "${pkgdir}/${MINGW_PREFIX}/share/doc/${_realname}/README.md"
}
